package com.fjzx.androidframe.network;

import android.text.TextUtils;
import android.util.SparseArray;

/**
 * @author xiongyongcong
 */
public class ResponseMap {
    public static final int UNKNOWN                 = -1;
    public static final int ERROR                   = 0;
    public static final int SUCCESS                 = 1;
    public static final int OK                      = 200;
    public static final int FREQUENT                = 207;
    public static final int LOGIN_FAIL              = 303;
    public static final int BAD_REQUEST             = 400;
    public static final int UNAUTHORIZED            = 401;
    public static final int FORBIDDEN               = 403;
    public static final int NOT_FOUND               = 404;
    public static final int REQUEST_TIMEOUT         = 408;
    public static final int CONFLICT                = 409;
    public static final int GONE                    = 410;
    public static final int LOCKED                  = 423;
    public static final int INTERNAL_SERVER_ERROR   = 500;
    public static final int BAD_GATEWAY             = 502;
    public static final int SERVICE_UNAVAILABLE     = 503;
    public static final int GATEWAY_TIMEOUT         = 504;

    private static SparseArray<String> responses = new SparseArray<>();

    static {
        responses.put(ERROR, "请求失败");
        responses.put(SUCCESS, "请求成功");
        responses.put(UNKNOWN, "未知错误,请联系管理员!");
        responses.put(OK, "请求成功");
        responses.put(FREQUENT, "频繁操作");
        responses.put(LOGIN_FAIL, "登录失败");
        responses.put(BAD_REQUEST, "请求无效");
        responses.put(UNAUTHORIZED, "您没有权限");
        responses.put(FORBIDDEN, "服务器拒绝访问");
        responses.put(NOT_FOUND, "找不到页面");
        responses.put(REQUEST_TIMEOUT, "请求超时");
        responses.put(CONFLICT, "发生冲突");
        responses.put(GONE, "接口已失效");
        responses.put(LOCKED, "已被锁定");
        responses.put(INTERNAL_SERVER_ERROR, "服务器出错");
        responses.put(BAD_GATEWAY, "服务器无响应");
        responses.put(SERVICE_UNAVAILABLE, "服务器无响应");
        responses.put(GATEWAY_TIMEOUT, "服务器响应超时");
    }

    public static String getReponseMessage(int code) {
        return TextUtils.isEmpty(responses.get(code)) ? "未知错误,请联系管理员" : responses.get(code);
    }

}
